package ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fy.fyzf.R;
import com.fy.fyzf.bean.HousesListBean;
import com.fy.fyzf.glideUtils.GlideUtils;
import com.fy.fyzf.utils.MathUtils;

/**
 * 首页列表
 */
public class HousesCollectionAdapter extends BaseQuickAdapter<HousesListBean.ListBean, BaseViewHolder> {

    private Context mContext;
    public HousesCollectionAdapter(Context context) {
        super(R.layout.item_house_collection);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, HousesListBean.ListBean item) {
        helper.addOnClickListener(R.id.share_wx);
        helper.addOnClickListener(R.id.share_pyq);
        helper.setText(R.id.tv_name, item.getAreaName()+" "+item.getHousingNo());
        helper.setText(R.id.tv_address, MathUtils.rvZeroAndDot(item.getHousingArea())+ "m² | " + item.getFloorName());
        String s;
        String price;
        if (null == item.getRentPrice()) {
            price = "0";
        } else {
            price = MathUtils.rvZeroAndDot(item.getRentPrice());
        }
        s = price + "元/m²/天";


        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(s);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FF7E00")), 0, price.length(), spannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#353535")), price.length(), s.length(), spannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        helper.setText(R.id.tv_price, spannableStringBuilder)
                .setText(R.id.tv_location, item.getSubwayName() + "地铁附近");
        GlideUtils.loadRoundedCornersImage(item.getHousingImage(),helper.getView(R.id.iv_logo),10);
    }
}
